package com.wenhao.meituan.interview;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @author Wenhao Tong
 * @create 2021-08-08 11:30
 */
public class Main5 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int k = scanner.nextInt();
        Map<Integer,TreeNode> map = new HashMap<>();
        map.put(0,null);
        for (int i = 1;i <= n;i++) {
            map.put(i,new TreeNode(i));
        }
        for (int i = 1;i <= n;i++) {
            TreeNode node = map.get(i);
            int left = scanner.nextInt();
            int right = scanner.nextInt();
            node.left = map.get(left);
            node.right = map.get(right);
            map.put(i,node);
        }
        for (int i = 0;i < m;i++) {
            int t = scanner.nextInt();
            TreeNode exchange = map.get(t);
            TreeNode temp = exchange.left;
            exchange.left = exchange.right;
            exchange.right = temp;
        }
        TreeNode root = map.get(k);
        midOrder(root);
    }

    private static void midOrder (TreeNode root) {
        if (root == null) {
            return;
        }
        midOrder(root.left);
        System.out.print(root.value + " ");
        midOrder(root.right);
    }
}

class TreeNode {
    int value;
    TreeNode left;
    TreeNode right;
    TreeNode(){};
    TreeNode(int value) {
        this.value = value;
    }
}
